Skip default evaluation and callbacks during resilient parsing#3356
Closed
barry3406 wants to merge 1 commit into
Closed
Skip default evaluation and callbacks during resilient parsing#3356barry3406 wants to merge 1 commit into
barry3406 wants to merge 1 commit into
Conversation
During shell completion, Context.resilient_parsing is set to True. Its documentation states that parsing happens without any interactivity or callback invocation, and that default values are ignored. However, ``Parameter.consume_value`` still called the ``default=`` callable and ``Parameter.process_value`` still invoked the parameter's ``callback``, which could produce unwanted side effects during tab-completion. Now both paths honor ``ctx.resilient_parsing``, matching the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During shell completion,
Context.resilient_parsingis set toTrue.Its documentation states:
However,
Parameter.consume_valuestill evaluated adefault=callableand
Parameter.process_valuestill invoked the parameter'scallbackwhile completion was running. This produced unwanted side effects during
tab-completion for callers that pass an expensive callable as
defaultor attach a
callbackwith side effects.Now both paths check
ctx.resilient_parsingand skip the default/callback,matching the documented behavior. The
_resolve_contextdocstring inshell_completion.pyalready said "it doesn't trigger input prompts orcallbacks" - this brings the implementation in line.
fixes #2614
Changes
Parameter.consume_value: skipself.get_default(ctx)whenctx.resilient_parsingisTrue.Parameter.process_value: skipself.callbackinvocation whenctx.resilient_parsingisTrue.Option.process_value: same skip for the bool-flag early-returnbranch.
tests/test_shell_completion.pycoveringdefault=callables, parameter
callback, and bool flagcallback.CHANGES.rstentry added under Unreleased.